<template>
	<view class="tabbar-container">
		<block>
			<view class="tabbar-item" v-for="(item,index) in tabbarList" :key="index"
				:class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)">
				<view class="item-top">
					<image :src="currentItem==item.id?item.selectedIconPath:item.iconPath"></image>
				</view>
				<view class="item-bottom" :class="[currentItem==item.id ? 'item-active' : '']">
					<text>{{item.text}}</text>
				</view>
			</view>
		</block>

	</view>
</template>

<script>
	export default {
		props: {
			currentPage: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				currentItem: 1,
				tabbarList: [{
					id: 0,
					iconPath: "/static/img/tabbar/one.png",
					text: "首页",
					selectedIconPath: "/static/img/tabbar/one_1.png",
					pagePath: "pages/tabbar/home/home",
					centerItem: false
				}, {
					id: 1,
					iconPath: "/static/img/tabbar/add.png",
					text: "",
					selectedIconPath: "/static/img/tabbar/add.png",
					pagePath: "pages/tabbar/classify/classify",
					centerItem: true
				}, {
					id: 2,
					iconPath: "/static/img/tabbar/three.png",
					text: "我的",
					selectedIconPath: "/static/img/tabbar/three_1.png",
					pagePath: "pages/tabbar/mine/mine",
					centerItem: false
				}],
			};
		},

		mounted() {
			this.currentItem = this.currentPage;
			uni.hideTabBar();
		},
		methods: {
			changeItem(item) {
				console.log('触发了',item);
				let _this = this;
				// _this.currentItem = item.id;  
				uni.switchTab({
					url: '/' + item.pagePath
				});
			}
		}
	}
</script>
<style>
	view {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

	.tabbar-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		/* height: 110rpx; */
		/* box-shadow: 0 0 5px #999; */
		box-shadow: 0rpx -4rpx 20rpx 0rpx rgba(0, 0, 0, 0.05);
		background-color: #fff;
		display: flex;
		justify-content: space-evenly;
		/* align-items: center; */
		padding: 5rpx 0;
		/* padding-bottom: 100rpx; */
		color: #999999;
		/* background-color: #fff; */
		z-index: 10;
	}

	.tabbar-container .tabbar-item {
		/* padding-bottom: 100rpx; */
		width: 20%;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;
	}

	.tabbar-container .item-active {
		color: #52CCCD;
	}
/* 中间的tabbar设置 */
	.tabbar-container .center-item {
		display: block;
		position: relative;
	}

	.tabbar-container .tabbar-item .item-top {
		width: 70rpx;
		height: 80rpx;
		padding: 10rpx;
	}

	.tabbar-container .center-item .item-top {
		flex-shrink: 0;
		width: 130rpx;
		height: 130rpx;
		position: absolute;
		top: -65rpx;
		left: calc(50% - 50rpx);
		border-radius: 50%;
		box-shadow: 0rpx 0 4rpx  #ccc;
		background-color: #ffffff;
	
	}

	.tabbar-container .tabbar-item .item-top image {
		width: 100%;
		height: 100%;
	}

	.tabbar-container .tabbar-item .item-bottom {
		font-size: 20rpx;
		width: 100%;
	}

	.tabbar-container .center-item .item-bottom {
		position: absolute;
		bottom: 5rpx;
	}

	/* 适配iphonex 有底部横条的 */
	@supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)) {
		.tabbar-container {
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
		}
	}
</style>